package com.excerise.queue;

import java.util.Arrays;

/**
 *
 *
 * @author Way on 2021/10/9
 */
public class Table {

    /**
     * 入栈数据
     */
    private final int[] stack;

    /**
     * 表示栈顶：初始化-1
     */
    private int top = -1;

    public Table() {
        stack = new int[4];
    }

    /**
     * 栈满
     * @return
     */
    public boolean isFull() {
        return top == 3;
    }

    /**
     * 空栈
     * @return
     */
    public boolean isEmpty() {
        return top == -1;
    }

    /**
     * 入栈
     * @param value
     */
    public void push(int value) {
        if (isFull()) {
            System.out.println("桌满");
            return;
        }

        top++;
        stack[top] = value;
    }

    /**
     * 出栈 - 此方法可可废弃
     * @return
     */
    public int pop() {
        if (isEmpty()) {
            return -1;
        }
        int value = stack[top];
        top--;
        return value;
    }

    /**
     * 遍历栈
     */
    public void list() {
        if (isEmpty()) {
            System.out.println("空桌");
            return;
        }
        System.out.println(Arrays.toString(stack));
//        for (int i = top; i >= 0; i--) {
//            System.out.printf("stack[%d]=%d\n", i, stack[i]);
//        }
    }
}
